package com.ysdwl.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysdwl.model.Bill;
import com.ysdwl.model.User;
import com.ysdwl.service.impl.UserService;

@WebServlet(urlPatterns = "/findUser")
public class FindUserServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			String userName = req.getParameter("userName");
			int sex = Integer.parseInt(req.getParameter("sex"));
			int userRole = Integer.parseInt(req.getParameter("userRole"));
			System.out.println(userName);
			
			User user = new User();
			user.setUserName(userName);;
			user.setGender(sex);;
			user.setUserRole(userRole);
			UserService userService = new UserService();
			List<User> list = userService.findAll(user);
			
			req.setAttribute("userList", list);
			req.getRequestDispatcher("userList.jsp").forward(req, resp);
			
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}

}
